package cn.online.taxi.common.test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

class Node {
    //元素类型为int的节点
    private int data;
    private Node next;
    //定义构造器
    public Node(int i, Node nt){
        data = i;
        next = nt;
    }
    public Node(int i){
        this(i,null);
    }
    public Node(){
        this(0,null);
    }
    //更改元素数值
    public void setData(int i){
        data = i;
    }
    //读取元素数值
    public int getData(){
        return data;
    }
    //更改元素的指向
    public void setNext(Node nt){
        next = nt;
    }
    //读取元素的指向
    public Node getNext(){
        return next;
    }
}

class JosephusNode {

    private Integer no;

    private Integer pwd;

    public Integer getNo() {
        return no;
    }

    public void setNo(Integer no) {
        this.no = no;
    }

    public Integer getPwd() {
        return pwd;
    }

    public void setPwd(Integer pwd) {
        this.pwd = pwd;
    }
}

class Linkedlist {
    private Node head;
    private Node tail;
    int size;
    //构造器
    public Linkedlist(){
        tail = head = null;
        size = 0;
    }

    //在链表头部增加节点
    public void addHead(Node hd){
        //如果使用该方法增加链表的第一个节点，则head=tail=hd，且next指向自身。
        if(size==0){
            hd.setNext(hd);
            tail = head = hd;
            size++;
        }
        else{
            tail.setNext(hd);
            hd.setNext(head);
            head = hd;
            size++;
        }
    }

    //在链表尾部增加节点
    public void addTail(Node tl){
        //如果使用该方法增加链表的第一个节点，则tail=head= hd，且next指向自身。
        if(size==0){
            tl.setNext(tl);
            tail = head = tl;
            size++;
        }
        else{
            tail.setNext(tl);
            tl.setNext(head);
            tail = tl;
            size++;
        }
    }

    //删除头部节点，被删掉的head将被自动回收
    public void delHead(){
        if(size>1){
            head = head.getNext();
            tail.setNext(head);
            size--;
        }
        else if(size==1){
            head = tail = null;
            size--;
        }
        else{
            System.out.println("There is no elements in the linked list.");
        }
    }

    //删除尾部节点
    public void delTail(){
        if(size>1){
            Node nd = new Node();
            nd = head;
            while(nd.getNext()!=tail){
                nd = nd.getNext();
            }
            nd.setNext(head);
            size--;
        }
        else if(size==1){
            head = tail = null;
            size--;
        }
        else{
            System.out.println("There is no elements in the linked list.");
        }
    }

    public void delTailIdentical() {

    }

    //打印全部节点
    public void printList(){
        Node nd = new Node();
        nd = head;
        try{
            while(nd.getNext()!=head){
                System.out.print(nd.getData());
                System.out.print(" ");
                nd = nd.getNext();
            }
            System.out.print(nd.getData());
//            System.out.print("->");
//            System.out.print(head.getData());
        }
        catch(Exception e){
            e.printStackTrace();
        }

    }
}

public class Josephus {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Linkedlist list = new Linkedlist();
        int n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            list.addTail(new Node(sc.nextInt()));

        }

//        for(int i = 0; i < n; i++) {
//            JosephusNode josephusNode = new JosephusNode();
//            josephusNode.setNo(i + 1);
//            josephusNode.setPwd((int) (1+Math.random()*(5-1+1)));
//            if(i == 0) {
//                Node head = new Node(josephusNode, null);
//                list.addHead(head);
//            }else {
//                list.addTail(new Node(josephusNode));
//            }
//        }
        list.printList();
        sc.close();
    }

}
